namespace Circle.Data.Migration
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using Circle.Domain.Entity;
    using Circle.Domain;
    using System.Configuration;

    internal sealed class CircleConfiguration : DbMigrationsConfiguration<CircleDbContext>
    {
        public CircleConfiguration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
        }

        protected override void Seed(CircleDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            base.Seed(context);

            if (context.Settings.Count() <= 0)
            {
                context.Database.ExecuteSqlCommand("ALTER TABLE ContentTopic DROP CONSTRAINT  [FK_dbo.ContentTopic_dbo.ContentComment_FirstCommentId];");
                context.Database.ExecuteSqlCommand("ALTER TABLE ContentTopic DROP CONSTRAINT  [FK_dbo.ContentTopic_dbo.ContentComment_LastCommentId];");

                context.Database.ExecuteSqlCommand("ALTER TABLE UploadFile DROP CONSTRAINT [FK_dbo.UploadFile_dbo.ContentComment_AttachId];");
                
                

                ConfigurationData configurationData = new ConfigurationData();

                configurationData.AddLanguageResourceKey(context);
                configurationData.AddSettings(context);

                configurationData.AddTopics(context);

                configurationData.AddFiles(context);

                configurationData.AddBannedWords(context);

                //configurationData.AddExternalSites(context);
                //configurationData.AddPermissions(context);
                //configurationData.AddFiles(context);
                //configurationData.AddCategories(context);
            }
        }

       
    }
}
